﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : AbstractPage {
	protected void Page_Load(object sender, EventArgs e) {

	}

	protected void btnCreateProfile_Click(object sender, EventArgs e) {
		this.Response.Redirect("profile.aspx");
	}

	protected void btnReenableProfile_Click(object sender, EventArgs e) {
		this.Response.Redirect("reenableProfile.aspx");
	}

	protected void btnLogin_Click(object sender, EventArgs e) {
		IProfileService profileService = new ProfileServiceImpl();

		try {
			User user = profileService.authenticate(this.txtUsername.Text, this.txtPassword.Text);

			if (user != null) {
				this.Session.Add(AbstractPage.SESSION_USER, user);

				//Redirect if everything's okay
				this.Response.Redirect("mainMenu.aspx");
			} else {
				this.Session.Remove(AbstractPage.SESSION_USER);
				this.lblLoginResult.Text = "Invalid email address or password";
			}
		} catch (BusinessException ex) {
			this.addMessages(ex);
		} catch (ServiceException ex) {
			this.addMessage(ex);
		}
	}
}
